package com.cardbaobao.cardbabyclient.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;

/**
 * Created by Jiangzx on 2017/9/16 16:07.
 */

public class UnbindCardDialog extends Dialog {
    public interface ClickedListener{
        void onEnsureClicked();
    }
    private ClickedListener listener;
    public void setClickedListener(ClickedListener listener){
        this.listener=listener;
    }

    public UnbindCardDialog(@NonNull Context context,@NonNull CharSequence cardInfo) {
        super(context,R.style.dialog);
        setContentView(R.layout.dialog_unbind_card);
        ((TextView)findViewById(R.id.tv_card)).setText(cardInfo);
        findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        findViewById(R.id.tv_ensure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if(listener!=null){
                    listener.onEnsureClicked();
                }
            }
        });
        Window window=getWindow();
        if(window!=null){
            //对话框宽度占屏幕4/5，对话框宽高比为600:490
            WindowManager.LayoutParams params=window.getAttributes();
            params.width=(int) (ScreenUtil.getScreenWidth()*0.8f);
            params.height=WindowManager.LayoutParams.WRAP_CONTENT;
            params.gravity= Gravity.CENTER;
            window.setAttributes(params);
        }
        setCanceledOnTouchOutside(false);
    }
}
